<?php
include "../lib/DAL/Lop.php";
class LopBLL
{
	function __construct()
	{
	}
	function __destruct()
	{
	}
	function setDMLopBLL($row)
	{
		$lop=new LopDAL();
		$lop->setdmlop($row['ma_lop'],$row['ten_lop'],$row['ngaytao_lop'],$row['id_khoahoc'],$row['ma_trungtam']);
		return $lop;
	}
	
	function setLopBLL($row)
	{
		$lop=new LopDAL();
		$lop->setlop($row['ma_lop'],$row['ten_lop'],$row['ngaytao_lop'],$row['nam_khoahoc'],$row['ten_trungtam']);
		return $lop;
	}
	function setKhoahoc($row)
	{
		$lop=new LopDAL();
		$lop->setkhoahoc($row['id_khoahoc'],$row['nam_khoahoc']);
		return $lop;
	}
	function setTrungtam($row)
	{
		$lop=new LopDAL();
		$lop->settrungtam($row['ma_trungtam'],$row['ten_trungtam']);
		return $lop;
	}
	public function getlop($ma_lop)
	{
		$sql="SELECT* FROM tbl_lop WHERE ma_lop='".$ma_lop."'";
		$sql_query=mysql_query($sql);
		$row=mysql_fetch_array($sql_query);
		return $this->setDMLopBLL($row);
	}
	
	public function insertlop($lop)
	{
		$sql="INSERT INTO tbl_lop(ma_lop,ten_lop,ngaytao_lop,id_khoahoc,ma_trungtam) 
				VALUES('".$lop->getma_lop()."','".$lop->getten_lop()."','".$lop->getngaytao_lop()."','".$lop->getid_khoahoc()."','".$lop->getma_trungtam()."') ";
				//print_r($sql);die();
		$kq=mysql_query($sql) or die(mysql_error());
		return $kq;
	}
	public function updatelop($lop)
	{
		$sql="UPDATE tbl_lop
				SET
					ma_lop='".$lop->getma_lop()."',
					ten_lop='".$lop->getten_lop()."',
					ngaytao_lop='".$lop->getngaytao_lop()."',
					id_khoahoc='".$lop->getid_khoahoc()."',
					ma_trungtam='".$lop->getma_trungtam()."'					
				";
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}
	public function deletelop($ma_lop)
	{
		$sql="DELETE  FROM tbl_lop WHERE ma_lop='".$ma_lop."'";
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}
	public function deleteall()
	{
		$sql="DELETE  FROM tbl_lop";
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}
	public function getlistlop()
	{
		$sql="SELECT ma_lop,ten_lop,ngaytao_lop,nam_khoahoc,ten_trungtam
			FROM tbl_lop AS a
			INNER JOIN tbl_trungtam AS b ON a.ma_trungtam=b.ma_trungtam
			INNER JOIN tbl_khoahoc AS c ON a.id_khoahoc=c.id_khoahoc
			";		
		$result=mysql_query($sql) or die(mysql_error());
		//echo $result;
		$arr_lop=array();
		while($row=mysql_fetch_array($result))
		{
			$arr_lop[]=$this->setLopBLL($row);
		}
		//print_r($arr_lop);die();
		return $arr_lop;
	}
	public function getkhoahoc()
	{
		$sql="SELECT id_khoahoc,nam_khoahoc FROM tbl_khoahoc";
		$result=mysql_query($sql) or die (mysql_error());
		$arr_khoahoc=array();
		while($row=mysql_fetch_array($result))
		{
			$arr_khoahoc[]=$this->setKhoahoc($row);
		}
		return $arr_khoahoc;
	}
	public function gettrungtam()
	{
		$sql="SELECT ma_trungtam,ten_trungtam FROM tbl_trungtam";
		$result=mysql_query($sql) or die(mysql_error());
		$arr_trungtam=array();
		while($row= mysql_fetch_array($result))
		{
			$arr_trungtam[]=$this->setTrungtam($row);
		}
		return $arr_trungtam;
	}
}
?>